package com.cmh.mynfc;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.content.Intent;
import android.nfc.NfcAdapter;
import android.nfc.Tag;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

public class MainActivity extends Activity {
    final String TAG = MainActivity.class.getSimpleName();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

//    @Override
//    public void onTagDiscovered(Tag detectedTag) {
//        Log.e(TAG, "收到NFC数据");
//        runOnUiThread(()->{
//            Toast.makeText(this, "收到NFC数据", Toast.LENGTH_SHORT).show();
//        });
//    }

    // 将Activity的launchMode设置成singleTop，这样当感应到NFC标签时不会重复打开页面，而是回调该方法
//    @Override
//    public void onNewIntent(Intent intent) {
//        super.onNewIntent(intent);
//        Log.e(TAG, "onNewIntent");
////        setIntent(intent);
////        String action = intent.getAction();
////        if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)// NDEF类型
////                || NfcAdapter.ACTION_TECH_DISCOVERED.equals(action)// 其他类型
////                || NfcAdapter.ACTION_TAG_DISCOVERED.equals(action)) {
////            // get tag
////            Tag detectedTag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
//////            String CardId = ByteArrayToHexString(detectedTag.getId());
//////            Log.d(TAG, "ID:" + CardId);
//////            writeTag(detectedTag);
////        } else {
////            //...
////        }
//
//
//        //write tag
//        //  writeTag(detectedTag);
//    }

//    @Override
//    public void onGetNfcText(String message) {
//
//    }
}